#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int q[N], tmp[N];
int n;

long long merge_find(int q[], int l, int r)
{
    if (l >= r)
        return 0;
    int mid = (l + r) >> 1;
    long long sum = merge_find(q, l, mid) + merge_find(q, mid + 1, r);

    int k = 0, i = l, j = mid + 1;
    while (i <= mid && j <= r)
    {
        if (q[i] > q[j])
        {
            sum += mid - i + 1;
            tmp[k++] = q[j++];
        }
        else
            tmp[k++] = q[i++];
    }
    while (i <= mid)
        tmp[k++] = q[i++];
    while (j <= r)
        tmp[k++] = q[j++];

    for (i = l, j = 0; i <= r; i++, j++)
        q[i] = tmp[j];

    return sum;
}

// int main(void)
// {
//     cin >> n;
//     for (int i = 0; i < n; i++)
//         cin >> q[i];
//     cout << merge_find(q, 0, n - 1);
// }